#include<stdio.h>
#include<string.h>
#include"global.h"
CI * selectsort(char key){                                                                                                                                                                                                                                                                                                
	CI *first,*tail,*p_min,*min,*p;
	first=NULL;
	while(head!=NULL){
		for(p=head,min=head;p->next!=NULL;p=p->next){
			if(key=='T'){
				if(strcmp(p->next->telphone,min->telphone)==1){
					p_min=p;
					min=p->next;
				}
			}
			else
				if(p->next->age>p->age){
					p_min=p;
					min=p->next;
				}

		}
		if(first==NULL){
			first=min;
			tail=min;
		}
		else{
			tail->next=min;
			tail=min;
		}
		if(min==head)
			head=head->next;
		else
			p_min->next=min->next;
	}
	if(first!=NULL)
		tail->next=NULL;
	head=first;
	return(head);
}

show(){
	int i=0;
	char key='Z';
	CI *p;
	p=NULL;
	while(key!='A'&&key!='O'&&key!='B'&&key!='T'){
		printf("\nO  :sort by Origion\nT  :sort by Telephone\nA  :sort by Age\nB  :Back\n");
		scanf("%c",&key);getchar();
		switch(key){
		case 'O':p=head;
			break;
		case 'T':p=selectsort(key);
			break;
		case 'A':p=selectsort(key);
			break;
		case 'B':return(0);
		default:printf("\nNo such selection!\n");
		}
	}
	printf("\n\tname\t\ttel\t\tsex\tage\tfamily phone\n");
	while(p!=NULL){
		i++;
		printf("\n%-8d%-16s%-16s%-8c%-8d%-16s\n",i,p->name,p->telphone,p->sex,p->age,p->phone);
//		printf("\n%s",p->tel);
		p=p->next;
	}
}
